<template>
  <div class="hello">
    {{ msg }}
    <div>{{jieshou}}</div>
    <input v-model="fa" />
    <div class="" @click="fasong">发送</div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data() {
    return {
      msg: 'Welcome to Your Vue.js App',
      fa: '',
      jieshou:''
    };
  },
  methods: {
    fasong() {
      //发送信息给服务端
      this.name++;
      this.$socket.emit('login', {
        username: this.fa,
        password: 'password'
      });
    }
  },
  mounted() {
    // this.$socket.emit('connect'); //在这里触发connect事件
  },
  sockets: {
    connect: function() {
      //这里是监听connect事件
      this.id = this.$socket.id;
      console.log(this.$socket.id,1)
    },
    relogin: function(val) {
      console.log(val,123);
      this.jieshou+=val.msg
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
